//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	FacadeMappingInfo.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Diagnostics;
using System.Web.Caching;

namespace Smart.Common
{
	/// <summary>
	/// Facade-List mapping info
	/// </summary>
	[DebuggerDisplay("FacadeMappingInfo {FacadeName}->{ListName}, {UseCache}")]
	public class FacadeMappingInfo
	{
		/// <summary>
		/// Facade name
		/// </summary>
		public string FacadeName { get; set; }

		/// <summary>
		/// List name
		/// </summary>
		public string ListName { get; set; }

		/// <summary>
		/// Cache user dependency
		/// </summary>
		public bool CacheUserDependent { get; set; }

		/// <summary>
		/// Cache absolute timeout
		/// </summary>
		public TimeSpan CacheAbsoluteTimeout { get; set; }

		/// <summary>
		/// Cache sliding expiration
		/// </summary>
		public TimeSpan CacheSlidingExpiration { get; set; }

		/// <summary>
		/// Cache priority
		/// </summary>
		public CacheItemPriority CachePriority { get; set; }

		/// <summary>
		/// Flag whether cache should be used
		/// </summary>
		public bool UseCache
		{
			get { return CacheAbsoluteTimeout.TotalSeconds > 1.0 || CacheSlidingExpiration.TotalSeconds > 1.0; }
		}

		/// <summary>
		/// Facade-List mapping info
		/// </summary>
		public FacadeMappingInfo(string facadeName, string listName)
		{
			FacadeName = facadeName;
			ListName = listName;

			CacheUserDependent = false;

			CacheAbsoluteTimeout = TimeSpan.MinValue;
			CacheSlidingExpiration = TimeSpan.MinValue;

			CachePriority = CacheItemPriority.BelowNormal;
		}
	}
}